<? if ($c = stack('name')) {

	$s = component_settings($c);

	?><div class="search">
	
	<? if (($q = trim(getdata('q'))) && ($q != $s['placeholder'])) { 
	
		ob_start(); ?><script type="text/javascript">
		
		function googleCallback (func, data) { window[func](data) }
		
		jQuery(function($) {
							 
			$.getJSON("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=<?=$s['api_key']?>&q=<?=urlencode($q.' site:'.$s['domain'])?>&callback=googleCallback&context=?",
			function(data){
				
				if (data.results.length) {
					 var ul = document.createElement("ul");
					 $.each(data.results, function(i, val){
								var li = document.createElement("li");
								li.innerHTML = '<a href="'+val.url+'" title="'+val.url+'" target="_blank">'+val.title+"</a> — "+val.content;                          
								ul.appendChild(li);
					 });
					 $('.search .results').html(ul);
					 
				} else {
					$('.search .results').html("<?=addslashes(str_replace("\r\n", " ", $s['e_nothing_found']))?>");
				}
			});
			
		})
		
		</script><? $SCRIPT[] = ob_get_clean(); ?>
	
		<div class="results"><?=$s['loading']?></div>
		
		
	<? } else { ?><?=$s['e_empty_search']?><? } ?>
	
	</div><?

	unstack();
} ?>